#!/bin/sh
#this file was used to mount hard disk device,most support three HDs
#根据uuid挂载硬盘，会先根据uuid记录文件中的挂载，当uuid改变时（换硬盘）
#会用新的uuid替换以前的，当挂成功后，如果uuid(硬盘)不变，挂载的目录不会
#改变,第一次挂载到那个目录下，以后都会挂载到此目录

sdx=`mount |head -1 |awk '{print substr($1,6,9)}'`
ls -l /dev/disk/by-uuid/ |sed '/'$sdx'/d' |awk '{print $9}' > /mnt/ssd1/uuid
sed -i '/^#/d' /mnt/ssd1/uuid

for ((i=2;i<5;i++))
do
	if [ -e /mnt/ssd$i/uuid ]; then
		uuid=`cat /mnt/ssd$i/uuid`
		if [ -n "$uuid" ]; then
			chkuuid=`grep $uuid /mnt/ssd1/uuid`
			if [ -n "$chkuuid" ]; then
				mount -t ext4 UUID=$uuid /mnt/ssd$i
				sed -i '/'$uuid'/d' /mnt/ssd1/uuid
			fi
		fi
		echo ssd$i exit
	fi
done

uuid=`cat /mnt/ssd1/uuid`

for i in $uuid
do
	str=`mount |grep ssd2`
	if [  -z "$str" ]; then
		echo $i > /mnt/ssd2/uuid
		mount -t ext4 UUID=$i /mnt/ssd2
		continue
	fi
	str=`mount |grep ssd3`
	if [  -z "$str" ]; then
		echo $i > /mnt/ssd3/uuid
		mount -t ext4 UUID=$i /mnt/ssd3
		continue
	fi
	str=`mount |grep ssd4`
	if [  -z "$str" ]; then
		echo $i > /mnt/ssd4/uuid
		mount -t ext4 UUID=$i /mnt/ssd4
		continue
	fi
done

